/*
 * Teknei 2014 - All rights reserved
 */
package com.teknei.acabus.example.services.impl;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;
import javax.ejb.TransactionAttribute;
import javax.ejb.TransactionAttributeType;

import com.teknei.acabus.PersistenceException;
import com.teknei.acabus.ServiceException;
import com.teknei.acabus.core.entities.TableC;
import com.teknei.acabus.core.persistence.dao.TableCDAO;
import com.teknei.acabus.core.services.assembler.TableCAssembler;
import com.teknei.acabus.dto.TableCDTO;
import com.teknei.acabus.example.services.TableCService;

/**
 * Session Bean implementation class TableCServiceBean
 * @author Jorge Amaro
 * @version 1.0
 * @since 1.0
 */
@Stateless
@TransactionAttribute(TransactionAttributeType.REQUIRES_NEW)
public class TableCServiceBean implements TableCService {

	@EJB
	private TableCDAO daoTableC;
	@EJB
	private TableCAssembler assemblerTableC;
	
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableCService#findAll()
     */
    @Override
    public List<TableCDTO> findAll() throws ServiceException{
    	try{
    		List<TableC> list = daoTableC.findAll();
    		List<TableCDTO> returnList = assemblerTableC.getDTOListTransform(list);
    		return returnList;
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in findAll:"+e.getMessage(), e);
    	}
    }
    
    
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableCService#update(com.teknei.acabus.dto.TableCDTO)
     */
    @Override
    public void update(TableCDTO entity) throws ServiceException{
    	try{
    		TableC c = assemblerTableC.getMappingTransform(entity);
    		daoTableC.update(c);
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in update:"+e.getMessage(), e);
    	}
    }
    
    
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableCService#save(com.teknei.acabus.dto.TableCDTO)
     */
    @Override
    public int save(TableCDTO entity) throws ServiceException{
    	try{
    		TableC c = assemblerTableC.getMappingTransform(entity);
    		TableC savedInstance = daoTableC.create(c);
    		return savedInstance.getIdField();
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in save:"+e.getMessage(), e);
    	}
    }
    
    /* (non-Javadoc)
     * @see com.teknei.acabus.example.services.TableCService#delete(com.teknei.acabus.dto.TableCDTO)
     */
    @Override
    public void delete(TableCDTO entity) throws ServiceException{
    	try{
    		TableC c = assemblerTableC.getMappingTransform(entity);
    		daoTableC.delete(c);
    	}catch(PersistenceException e){
    		throw new ServiceException("Error in delete:"+e.getMessage(), e);
    	}
    }

	/**
	 * @return the daoTableC
	 */
	public TableCDAO getDaoTableC() {
		return daoTableC;
	}

	/**
	 * @param daoTableC the daoTableC to set
	 */
	public void setDaoTableC(TableCDAO daoTableC) {
		this.daoTableC = daoTableC;
	}

    
}
